#ifndef HTTPSERVER_H
#define HTTPSERVER_H
#include<QTcpServer>
#include <QObject>
#include<QTcpSocket>
#include <QUrlQuery>
#include <QJsonParseError>
#include <QJsonObject>

class HttpServer : public QTcpServer
{
    Q_OBJECT
public:
    HttpServer();


protected:
    //处理新连接
    //当 QTcpServer 监听的端口接收到新的客户端连接请求时,incomingConnection 会被触发调用
    void incomingConnection(qintptr handle) override;

    void newConnection();

private slots:
    //处理客户端请求
    void handleRequest();

private:
    // 解析 HTTP 请求（返回方法、路径、参数、请求体）
    void parseHttpRequest(QTcpSocket *socket, QString &method, QString &path,
                          QMap<QString, QString> &params, QString &body);
    // 构造 HTTP 响应（状态码、头部、正文）
    void sendResponse(QTcpSocket *socket, int statusCode, const QString &contentType,
                      const QByteArray &body);
};

#endif // HTTPSERVER_H
